package JavaEE_notes.common_API.Thread.pojo;

import java.util.concurrent.Callable;

/**
 * @author TaiZai
 * @data 2024/9/24 17:42
 */
public class MyCallable implements Callable<String> {
    private int n;
    public MyCallable(int n) {
        this.n = n;
    }

    @Override
    public String call() throws Exception {
        // 任务执行的代码，描述线程执行的任务，返回线程执行的结果
        int sum = 0;
        for (int i = 0; i <= n; i++) {
            sum += i;
        }
        // return "MyCallable线程求出了1~" + n + "的和为" + sum;
        return Thread.currentThread().getName() + "求出了1~" + n + "的和为" + sum;
    }
}
